import type { Context } from 'koa';
import type { PipelineStage } from 'mongoose';
import { SplitPageDto } from '@/dtos/splitPage.dto';
import { ActivityService } from '@/services/activity';
import { UserRoles, UserStatus } from '@/enums/userEnums';

// 注册
export const activityListController = async (ctx: Context) => {
  const input = ctx.request.query;
  const {
    page = 1,
    pageSize = 10
  } = await ctx.vailParams<SplitPageDto>(SplitPageDto, input);

  const filter: PipelineStage = {
    $match: {
      'creator.role': { $ne: UserRoles.admin },
      'creator.status': { $eq: UserStatus.enable }
    }
  }

  const result = await ActivityService.getActivities({
    page,
    pageSize,
    // filters: [filter]
  });

  ctx.sendSuccess({
    page,
    pageSize,
    list: result
  });
}